package com.waji.local;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.Environment;

import com.waji.local.SharedPrefer;

public class SaveLocation {

	public static void save(Context context, double longitude2, double latitude2) {

		try {
			SharedPrefer.SaveLongitude(context, longitude2);
			SharedPrefer.SaveLatitude(context, latitude2);
            String s = "" + longitude2 + "\n " + latitude2;

			SimpleDateFormat formatter = new SimpleDateFormat("yyyy—MM—dd");
			SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss ");

			Date curDate = new Date(System.currentTimeMillis());
			String str = formatter.format(curDate);
			String str1 = formatter1.format(curDate);

			String hour = str1.split(":")[0];
			int inthour = Integer.parseInt(hour);

			int hours = SharedPrefer.Readhour(context);

			if (inthour != hours) {
				SharedPrefer.Savehour(context, inthour);

				File mFile = new File(Environment.getExternalStorageDirectory()
						.getAbsoluteFile() + "/" + str + "位置");

				if (!mFile.exists()) {
					mFile.mkdir();
				}
				File locationFile = new File(mFile + "/" + str1 + ".txt");
				byte[] sb = s.getBytes();
				FileOutputStream fos = new FileOutputStream(locationFile);
				fos.write(sb);
				fos.close();
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}

	}
}
